<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function ListNode(val) {
        this.val = val;
        this.next = null;
    }

    let Node1 = new ListNode(1)
    let Node2 = new ListNode(2)
    let Node3 = new ListNode(3)
    let Node4 = new ListNode(4)
    let Node5 = new ListNode(5)
    Node1.next = Node2
    Node2.next = Node3
    Node3.next = Node4
    Node4.next = Node5
    let reverseList = (head) => {
        debugger
        let reverse = (pre, cur) => {
            if (!cur) return pre;
            // 保存 next 节点
            let next = cur.next;
            cur.next = pre;
            reverse(cur, next);
        }
        return reverse(null, head);
    }
    console.log(reverseList(Node1));
</script>

</html>